﻿@model QuanLySanXuat.Models.ProductModelFormModels
@{
    ViewBag.Title = "Mẫu sản phẩm";
}
<link href="@Url.Content("~/ContentTMT/dateui.css")" rel="stylesheet" />
<script type="text/javascript">
    $(document).ready(function () {
        $(function () {
            $("#Date").datepicker();
            $("#Date").datepicker("option", "dateFormat", "dd/mm/yy");
        });
    });
</script>
<script src="~/Content/ckfinder/ckfinder.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#CheckValid').bootstrapValidator({
            message: 'This value is not valid',
            excluded: [':disabled'],
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                Code: {
                    validators: {
                        notEmpty: {
                            message: 'Ký hiệu không để trống'
                        }
                    }
                },
                CategoryID: {
                    validators: {
                        notEmpty: {
                            message: 'Phải chọn nhóm sản phẩm'
                        }
                    }
                },
                ProductTypeID: {
                    validators: {
                        notEmpty: {
                            message: 'Phải chọn loại sản phẩm'
                        }
                    }
                },
            }
        }).on('success.form.bv', function (e) {
            // Prevent form submission
            e.preventDefault();

            // Get the form instance
            var $form = $(e.target);

            // Get the BootstrapValidator instance
            var bv = $form.data('bootstrapValidator');
            $("#Date").datepicker("option", "dateFormat", "mm/dd/yy");
            // Use Ajax to submit form data
            $.ajax({
                type: "POST",
                url: '@Url.Action("Save", "ProductModel")',
                async: false,
                cache: false,
                data: $('#CheckValid').serialize(),
                success: function (result) {
                    location.href = '@Url.Action("Index", "ProductModel")'
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.status);
                    alert(xhr.responseText);
                    alert(thrownError);
                }
            });
        });
    });
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $(function () {
            $("#Date").datepicker();
            $("#CatDate").datepicker();
        });
        $("#btnSelectImg").click(function () {
            var finder = new CKFinder();
            finder.selectActionFunction = function (fileUrl) {
                var str = $('#Catalogue').val();
                if (str == "") {
                    $('#Catalogue').val(fileUrl);
                }
                else {
                    $('#Catalogue').val(str + ", " + fileUrl);
                }
                $('#imageGood').show();
                $('#imageGood').attr('src', fileUrl);
            };
            finder.popup();
        });
    });

    function AddDesign(element) {
        UpdateDesignDetail(element);
    }

    function SetFile(element) {
        var tbody = $(element).closest('tr');
        var finder = new CKFinder();
        finder.selectActionFunction = function (fileUrl) {
            $('.desginFile', tbody).val(fileUrl);
        };
        finder.popup();
    }

    function UpdateDesignDetail(element) {
        var tbody = $(element).closest('tr');
        var code = $(".code", tbody).val();
        var name = $(".name", tbody).val();
        var des = $(".description", tbody).val();
        var type = $(".type", tbody).val();
        var dfile = $(".desginFile", tbody).val();
        var designID = $(".designID", tbody).val();
        var productID = $("#ID").val();

        if (code == "" || name == "" || type == "") {
            alert("Bạn chưa nhập đủ thông tin");
        }
        else {
            $.ajax({
                type: "POST",
                url: '@Url.Action("UpdateDesignDetail", "ProductModel")',
                async: false,
                cache: false,
                data: { ID: designID, Code: code, Name: name, Description: des, DesignFile: dfile, Type: type, ProductID: productID },
                success: function (result) {
                    alert("Bạn thêm chi tiết thiết kế thành công");
                    $('.designID', tbody).val(result);
                    //hiển thị các form chi tiết
                    $('.formChiTiet').show();
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.status);
                    alert(xhr.responseText);
                    alert(thrownError);
                }
            });
        }
        GetDesignDetail($('.designID', tbody).val(), $("#ID").val());
    }
</script>
<div id="breadcrumb">
    <div class="container">
        <div id="con_top">
            <div class="c_container">
                <h3>Mẫu sản phẩm</h3>
            </div>
        </div>
    </div>
</div>

@if (Model == null)
{
    <form class="form-horizontal" role="form" id="CheckValid" style="margin-top: 10px;">
        <div class="col-sm-6">
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Mã mẫu sản phẩm (*)</label>
                <div class="col-sm-8">
                    <input type="hidden" id="ID" name="ID" value="0" />
                    <input type="text" class="form-control" id="Code" name="Code" placeholder="Code">
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Tên mẫu sản phẩm (*)</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="Name" name="Name" placeholder="Name">
                </div>
            </div>
            <div class="form-group">
                <label for="ProductTypeID" class="col-sm-4 control-label">Nhóm sản phẩm (*)</label>
                <div class="col-sm-8">
                    @Html.DropDownList("CategoryID", new SelectList(ViewData["Category"] as IEnumerable<Data.Models.Category>, "ID", "Name"), new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="Color" class="col-sm-4 control-label">Loại sản phẩm (*)</label>
                <div class="col-sm-8">
                    @Html.DropDownList("ProductTypeID", new SelectList(ViewData["ProductType"] as IEnumerable<Data.Models.ProductType>, "ID", "Name"), new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="Color" class="col-sm-4 control-label"></label>
                <div class="col-sm-8">
                    <input type="image" id="imageGood" width="100px;" height="100px;" value="Anh minh hoa" hidden />
                </div>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label for="Description" class="col-sm-3 control-label">Mô tả đặc trưng</label>
                <div class="col-sm-8">
                    <textarea id="Description" name="Description" class="form-control" rows="5" placeholder="Mô tả"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-3 control-label">Người thiết kế</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="Author" name="Author" placeholder="Author">
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-3 control-label">Ngày xuất bản</label>
                <div class="col-sm-8">
                    <div class='input-group date'>
                        <input type="text" class="form-control" id="Date" name="Date">
                    </div>

                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-3 control-label">Catalogue</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="Catalogue" name="Catalogue" placeholder="Catalogue">
                    <input type="button" id="btnSelectImg" value="Chọn ..." />
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="c_container col-sm-10 col-sm-offset-1">
                <div id="form_body">
                    <table id="tblDesgin">
                        <thead>
                            <tr>
                                <th style="width: 90px;"><span>Ký hiệu</span></th>
                                <th style="width: 150px;"><span>Tên</span></th>
                                <th style="width: 80px;"><span>Kiểu</span></th>
                                <th style="width: 140px;"><span>Mô tả</span></th>
                                <th style="width: 100px;"><span>File thiết kế</span></th>
                                <th style="width: 20px;"><span></span></th>
                                <th style="width: 20px;"><span></span></th>
                            </tr>
                        </thead>
                        <tbody id="insertRow">
                            <tr>
                                <td>
                                    <input type="hidden" id="designID" name="designID" value="0" class="designID" />
                                    <input type="text" id="CodeDesgin" name="CodeDesgin" class="txt1 code">
                                </td>
                                <td>
                                    <input type="text" id="NameDesign" name="NameDesign" class="txt1 name">
                                </td>
                                <td>
                                    @Html.DropDownList("TypeID", new SelectList(new[] { new { ID = 0, Name = "Hoàn thiện" }, new { ID = 1, Name = "Chưa hoàn thiện" } }, "ID", "Name"), new { @class = "span2 col-sm-1 form-control type" })
                                </td>
                                <td>
                                    <input type="text" id="DescriptionDesign" name="DescriptionDesign" class="txt1 description">
                                </td>
                                <td>
                                    <input type="text" id="DesignFile" name="DesignFile" class="txt1 desginFile" onclick="SetFile(this);" placeholder="Chọn file ...">
                                </td>
                                <td>
                                    <div class="addproduct" id="adddesign" onclick="AddDesign(this);">Lưu</div>
                                </td>
                                <td>
                                    <div class="remove" id="delRow" onclick="RemoveRow(this,'tblDesgin');"></div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="tablefooter">
                    <div class="pos1">
                        <input type="button" id="addline_CreateDesgign" class="addline" value="Thêm chi tiết thiết kế">
                    </div>
                </div>
                <div class="cleardiv"></div>
                <div class="formChiTiet">
                    <div id="form_body">
                        <table id="tblMaterial">
                            <thead>
                                <tr>
                                    <th style="width: 90px;"><span>Ký hiệu</span></th>
                                    <th style="width: 150px;"><span>Tên</span></th>
                                    <th style="width: 150px;"><span>Mã chi tiết thiết kế</span></th>
                                    <th style="width: 140px;"><span>Loại nguyên vật liệu</span></th>
                                    <th style="width: 100px;"><span>Đơn vị tính</span></th>
                                    <th style="width: 50px;"><span>Số lượng</span></th>
                                    <th style="width: 20px;"><span></span></th>
                                </tr>
                            </thead>
                            <tbody id="insertRow">
                                <tr>
                                    <td>
                                        <input type="hidden" id="MaterialFormulaID" name="MaterialFormulaID" value="0" class="MaterialFormulaID" />
                                        <input type="text" id="CodeMaterialFormula" name="CodeMaterialFormula" class="txt1 codematerial code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameMaterialFormula" name="NameMaterialFormula" class="txt1 namematerial name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("MaterialDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code"), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("MaterialTypeID", new SelectList(ViewData["MaterialType"] as IEnumerable<Data.Models.MaterialType>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblMaterial');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("MaterialUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityMaterialFormula" name="QuantityMaterialFormula" class="txt1 quantitymaterial quantity">
                                    </td>

                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblMaterial');"></div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="tablefooter">
                        <div class="pos1">
                            <input type="button" id="addline_CreateMaterial" class="addline" value="Thêm nguyên vật liệu">
                        </div>
                    </div>
                    <div class="cleardiv"></div>
                    <div id="form_body">
                        <table id="tblTool">
                            <thead>
                                <tr>
                                    <th style="width: 90px;"><span>Ký hiệu</span></th>
                                    <th style="width: 150px;"><span>Tên</span></th>
                                    <th style="width: 150px;"><span>Mã chi tiết thiết kế</span></th>
                                    <th style="width: 140px;"><span>Loại công cụ sản xuất</span></th>
                                    <th style="width: 100px;"><span>Đơn vị tính</span></th>
                                    <th style="width: 50px;"><span>Số lượng</span></th>
                                    <th style="width: 20px;"><span></span></th>
                                </tr>
                            </thead>
                            <tbody id="insertRow">
                                <tr>
                                    <td>
                                        <input type="hidden" id="ToolFormulaID" name="ToolFormulaID" value="0" class="ToolFormulaID" />
                                        <input type="text" id="CodeToolFormula" name="CodeToolFormula" class="txt1 codeTool code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameToolFormula" name="NameToolFormula" class="txt1 nameTool name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("ToolDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code"), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("ToolTypeID", new SelectList(ViewData["ToolType"] as IEnumerable<Data.Models.ToolType>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblTool');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("ToolUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityToolFormula" name="QuantityToolFormula" class="txt1 quantityTool quantity">
                                    </td>

                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblTool');"></div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="tablefooter">
                        <div class="pos1">
                            <input type="button" id="addline_CreateTool" class="addline" value="Thêm công cụ sản xuất">
                        </div>
                    </div>
                    <div class="cleardiv"></div>
                    <div id="form_body">
                        <table id="tblLabour">
                            <thead>
                                <tr>
                                    <th style="width: 90px;"><span>Ký hiệu</span></th>
                                    <th style="width: 150px;"><span>Tên</span></th>
                                    <th style="width: 150px;"><span>Mã chi tiết thiết kế</span></th>
                                    <th style="width: 140px;"><span>Mã bậc thợ</span></th>
                                    <th style="width: 100px;"><span>Đơn vị tính</span></th>
                                    <th style="width: 50px;"><span>Số lượng</span></th>
                                    <th style="width: 20px;"><span></span></th>
                                </tr>
                            </thead>
                            <tbody id="insertRow">
                                <tr>
                                    <td>
                                        <input type="hidden" id="LabourFormulaID" name="LabourFormulaID" value="0" class="LabourFormulaID" />
                                        <input type="text" id="CodeLabourFormula" name="CodeLabourFormula" class="txt1 codeLabour code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameLabourFormula" name="NameLabourFormula" class="txt1 nameLabour name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("LabourDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code"), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("LabourID", new SelectList(ViewData["Labour"] as IEnumerable<Data.Models.WorkerLevel>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblLabour');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("LabourUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityLabourFormula" name="QuantityLabourFormula" class="txt1 quantityLabour quantity">
                                    </td>

                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblLabour');"></div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="tablefooter">
                        <div class="pos1">
                            <input type="button" id="addline_CreateLabour" class="addline" value="Thêm nhân công">
                        </div>
                    </div>
                    <div class="cleardiv"></div>
                    <div id="form_body">
                        <table id="tblOther">
                            <thead>
                                <tr>
                                    <th style="width: 90px;"><span>Ký hiệu</span></th>
                                    <th style="width: 150px;"><span>Tên</span></th>
                                    <th style="width: 150px;"><span>Mã chi tiết thiết kế</span></th>
                                    <th style="width: 140px;"><span>Chi phí khác</span></th>
                                    <th style="width: 100px;"><span>Đơn vị tính</span></th>
                                    <th style="width: 50px;"><span>Số lượng</span></th>
                                    <th style="width: 20px;"><span></span></th>
                                </tr>
                            </thead>
                            <tbody id="insertRow">
                                <tr>
                                    <td>
                                        <input type="hidden" id="OtherFormulaID" name="OtherFormulaID" value="0" class="OtherFormulaID" />
                                        <input type="text" id="CodeOtherFormula" name="CodeOtherFormula" class="txt1 codeOther code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameOtherFormula" name="NameOtherFormula" class="txt1 nameOther name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("OtherDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code"), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("OtherID", new SelectList(ViewData["Other"] as IEnumerable<Data.Models.OtherCost>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblOther');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("OtherUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityOtherFormula" name="QuantityOtherFormula" class="txt1 quantityOther quantity">
                                    </td>
                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblOther');"></div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="tablefooter">
                        <div class="pos1">
                            <input type="button" id="addline_CreateOther" class="addline" value="Thêm chi phí khác">
                        </div>
                    </div>
                    <div class="cleardiv"></div>
                    <div class="btn-group">
                        <div class="btn-group">
                            <button id="btnSaveSale" type="submit" class="btn btn-defaultxero">Lưu</button>
                        </div>
                    </div>
                    <div class="btn-group">
                        <button id="btnCancelSale" type="button" onclick="javascript: location.href = '/ProductModel';" class="btn btn-defaultxero">Hủy</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
}
else
{
    <form class="form-horizontal" role="form" id="CheckValid" style="margin-top: 10px;">
        <div class="col-sm-6">
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Mã mẫu sản phẩm (*)</label>
                <div class="col-sm-8">
                    <input type="hidden" id="ID" name="ID" value="@Model.ID" />
                    <input type="text" class="form-control" id="Code" name="Code" placeholder="Code" value="@Model.Code">
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Tên mẫu sản phẩm (*)</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="Name" name="Name" placeholder="Name" value="@Model.Name">
                </div>
            </div>
            <div class="form-group">
                <label for="ProductTypeID" class="col-sm-4 control-label">Nhóm sản phẩm (*)</label>
                <div class="col-sm-8">
                    @Html.DropDownList("CategoryID", new SelectList(ViewData["Category"] as IEnumerable<Data.Models.Category>, "ID", "Name", Model.CategoryID), new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="Color" class="col-sm-4 control-label">Loại sản phẩm(*)</label>
                <div class="col-sm-8">
                    @Html.DropDownList("ProductTypeID", new SelectList(ViewData["ProductType"] as IEnumerable<Data.Models.ProductType>, "ID", "Name", Model.ProductTypeID), new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="Color" class="col-sm-4 control-label"></label>
                <div class="col-sm-8">
                    <input type="image" id="imageGood" width="100px;" height="100px;" value="Anh minh hoa" hidden />
                </div>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label for="Description" class="col-sm-3 control-label">Mô tả đặc trưng</label>
                <div class="col-sm-8">
                    <textarea id="Description" name="Description" class="form-control" rows="5" placeholder="Mô tả">@Model.Description</textarea>
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-3 control-label">Người thiết kế</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="Author" name="Author" placeholder="Author" value="@Model.Author">
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-3 control-label">Ngày xuất bản</label>
                <div class="col-sm-8">
                    <div class='input-group date'>
                        <input type="text" class="form-control" id="Date" name="Date" value="@Convert.ToDateTime(Model.Date).ToShortDateString()">
                    </div>

                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-3 control-label">Catalogue</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="Catalogue" name="Catalogue" placeholder="Catalogue" value="@Model.Catalogue">
                    <input type="button" id="btnSelectImg" value="Chọn ..." />
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="c_container col-sm-10 col-sm-offset-1">
                <div id="form_body">
                    <table id="tblDesgin">
                        <thead>
                            <tr>
                                <th style="width: 90px;"><span>Ký hiệu</span></th>
                                <th style="width: 150px;"><span>Tên</span></th>
                                <th style="width: 80px;"><span>Kiểu</span></th>
                                <th style="width: 140px;"><span>Mô tả</span></th>
                                <th style="width: 100px;"><span>File thiết kế</span></th>
                                <th style="width: 20px;"><span></span></th>
                                <th style="width: 20px;"><span></span></th>
                            </tr>
                        </thead>
                        <tbody id="insertRow">
                            @if (Model.DesignDetailFormModels != null)
                            {
                                foreach (var item in Model.DesignDetailFormModels)
                                {
                                <tr>
                                    <td>
                                        <input type="hidden" id="designID" name="designID" value="@item.ID" class="designID" />
                                        <input type="text" id="CodeDesgin" name="CodeDesgin" class="txt1 code"value="@item.Code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameDesign" name="NameDesign" class="txt1 name" value="@item.Name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("TypeID", new SelectList(new[] { new { ID = 0, Name = "Toàn bộ" }, new { ID = 1, Name = "Chi tiết" } }, "ID", "Name", item.Type), "Chọn kiểu", new { @class = "span2 col-sm-1 form-control type" })
                                    </td>
                                    <td>
                                        <input type="text" id="DescriptionDesign" name="DescriptionDesign" class="txt1 description" value="@item.Description">
                                    </td>
                                    <td>
                                        <input type="text" id="DesignFile" name="DesignFile" class="txt1 desginFile" onclick="SetFile(this);" value="@item.DesignFile">
                                    </td>
                                    <td>
                                        <div class="addproduct" id="adddesign" onclick="AddDesign(this);">Lưu</div>
                                    </td>
                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblDesgin');"></div>
                                    </td>
                                </tr>
                                }

                            }
                            else
                            { 
                                <tr>
                                    <td>
                                        <input type="hidden" id="designID" name="designID" value="0" class="designID" />
                                        <input type="text" id="CodeDesgin" name="CodeDesgin" class="txt1 code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameDesign" name="NameDesign" class="txt1 name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("TypeID", new SelectList(new[] { new { ID = 0, Name = "Hoàn thiện" }, new { ID = 1, Name = "Chưa hoàn thiện" } }, "ID", "Name"), new { @class = "span2 col-sm-1 form-control type" })
                                    </td>
                                    <td>
                                        <input type="text" id="DescriptionDesign" name="DescriptionDesign" class="txt1 description">
                                    </td>
                                    <td>
                                        <input type="text" id="DesignFile" name="DesignFile" class="txt1 desginFile" onclick="SetFile(this);">
                                    </td>
                                    <td>
                                        <div class="addproduct" id="adddesign" onclick="AddDesign(this);">Lưu</div>
                                    </td>
                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblDesgin');"></div>
                                    </td>
                                </tr>
                            }

                        </tbody>
                    </table>
                </div>
                <div class="tablefooter">
                    <div class="pos1">
                        <input type="button" id="addline_CreateDesgign" class="addline" value="Thêm chi tiết thiết kế">
                    </div>
                </div>
                <div class="cleardiv"></div>

                <div id="form_body">
                    <table id="tblMaterial">
                        <thead>
                            <tr>
                                <th style="width: 90px;"><span>Ký hiệu</span></th>
                                <th style="width: 150px;"><span>Tên</span></th>
                                <th style="width: 150px;"><span>Mã chi tiết thiết kế</span></th>
                                <th style="width: 140px;"><span>Loại nguyên vật liệu</span></th>
                                <th style="width: 100px;"><span>Đơn vị tính</span></th>
                                <th style="width: 50px;"><span>Số lượng</span></th>
                                <th style="width: 20px;"><span></span></th>
                            </tr>
                        </thead>
                        <tbody id="insertRow">
                            @if (Model.MaterialFormulaFormModels != null)
                            {
                                if (Model.MaterialFormulaFormModels.Count() > 0)
                                {
                                    foreach (var item in Model.MaterialFormulaFormModels)
                                    {
                                <tr>
                                    <td>
                                        <input type="hidden" id="MaterialFormulaID" name="MaterialFormulaID" value="@item.ID" class="MaterialFormulaID" />
                                        <input type="text" id="CodeMaterialFormula" name="CodeMaterialFormula" class="txt1 codematerial code" value="@item.Code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameMaterialFormula" name="NameMaterialFormula" class="txt1 namematerial name" value="@item.Name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("MaterialDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code", item.DesignDetailID), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("MaterialTypeID", new SelectList(ViewData["MaterialType"] as IEnumerable<Data.Models.MaterialType>, "ID", "Name", item.MaterialTypeID), new { @class = "span2 col-sm-1 form-control uom",@onchange="GetUOM(this,'tblMaterial');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("MaterialUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name", item.UOMID), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityMaterialFormula" name="QuantityMaterialFormula" class="txt1 quantitymaterial quantity" value="@item.Quantity">
                                    </td>

                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblMaterial');"></div>
                                    </td>
                                </tr>
                                    }
                                }
                                else
                                {
                                <tr>
                                    <td>
                                        <input type="hidden" id="MaterialFormulaID" name="MaterialFormulaID" value="0" class="MaterialFormulaID" />
                                        <input type="text" id="CodeMaterialFormula" name="CodeMaterialFormula" class="txt1 codematerial code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameMaterialFormula" name="NameMaterialFormula" class="txt1 namematerial name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("MaterialDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code"), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("MaterialTypeID", new SelectList(ViewData["MaterialType"] as IEnumerable<Data.Models.MaterialType>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control uom",@onchange="GetUOM(this,'tblMaterial');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("MaterialUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityMaterialFormula" name="QuantityMaterialFormula" class="txt1 quantitymaterial quantity">
                                    </td>

                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblMaterial');"></div>
                                    </td>
                                </tr>
                                }

                            }
                            else
                            { 
                                <tr>
                                    <td>
                                        <input type="hidden" id="MaterialFormulaID" name="MaterialFormulaID" value="0" class="MaterialFormulaID" />
                                        <input type="text" id="CodeMaterialFormula" name="CodeMaterialFormula" class="txt1 codematerial code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameMaterialFormula" name="NameMaterialFormula" class="txt1 namematerial name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("MaterialDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code"), new { @class = "span2 col-sm-1 form-control desgingchange " })
                                    </td>
                                    <td>
                                        @Html.DropDownList("MaterialTypeID", new SelectList(ViewData["MaterialType"] as IEnumerable<Data.Models.MaterialType>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblMaterial');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("MaterialUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityMaterialFormula" name="QuantityMaterialFormula" class="txt1 quantitymaterial quantity">
                                    </td>

                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblMaterial');"></div>
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
                <div class="tablefooter">
                    <div class="pos1">
                        <input type="button" id="addline_CreateMaterial" class="addline" value="Thêm nguyên vật liệu">
                    </div>
                </div>
                <div class="cleardiv"></div>
                <div id="form_body">
                    <table id="tblTool">
                        <thead>
                            <tr>
                                <th style="width: 90px;"><span>Ký hiệu</span></th>
                                <th style="width: 150px;"><span>Tên</span></th>
                                <th style="width: 150px;"><span>Mã chi tiết thiết kế</span></th>
                                <th style="width: 140px;"><span>Loại công cụ sản xuất</span></th>
                                <th style="width: 100px;"><span>Đơn vị tính</span></th>
                                <th style="width: 50px;"><span>Số lượng</span></th>
                                <th style="width: 20px;"><span></span></th>
                            </tr>
                        </thead>
                        <tbody id="insertRow">
                            @if (Model.ToolFormulaFormModels != null)
                            {
                                if (Model.ToolFormulaFormModels.Count() > 0)
                                {
                                    foreach (var item in Model.ToolFormulaFormModels)
                                    {
                                <tr>
                                    <td>
                                        <input type="hidden" id="ToolFormulaID" name="ToolFormulaID" value="@item.ID" class="ToolFormulaID" />
                                        <input type="text" id="CodeToolFormula" name="CodeToolFormula" class="txt1 codeTool code" value="@item.Code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameToolFormula" name="NameToolFormula" class="txt1 nameTool name" value="@item.Name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("ToolDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code", item.DesignDetailID), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("ToolTypeID", new SelectList(ViewData["ToolType"] as IEnumerable<Data.Models.ToolType>, "ID", "Name", item.ToolTypeID), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblTool');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("ToolUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name", item.UOMID), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityToolFormula" name="QuantityToolFormula" class="txt1 quantityTool quantity" value="@item.Quantity">
                                    </td>
                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblTool');"></div>
                                    </td>
                                </tr>
                                    }
                                }
                                else
                                {
                                <tr>
                                    <td>
                                        <input type="hidden" id="ToolFormulaID" name="ToolFormulaID" value="0" class="ToolFormulaID" />
                                        <input type="text" id="CodeToolFormula" name="CodeToolFormula" class="txt1 codeTool code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameToolFormula" name="NameToolFormula" class="txt1 nameTool name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("ToolDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code"), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("ToolTypeID", new SelectList(ViewData["ToolType"] as IEnumerable<Data.Models.ToolType>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblTool');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("ToolUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityToolFormula" name="QuantityToolFormula" class="txt1 quantityTool quantity">
                                    </td>
                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblTool');"></div>
                                    </td>
                                </tr>
                                }

                            }
                            else
                            { 
                                <tr>
                                    <td>
                                        <input type="hidden" id="ToolFormulaID" name="ToolFormulaID" value="0" class="ToolFormulaID" />
                                        <input type="text" id="CodeToolFormula" name="CodeToolFormula" class="txt1 codeTool code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameToolFormula" name="NameToolFormula" class="txt1 nameTool name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("ToolDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code"), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("ToolTypeID", new SelectList(ViewData["ToolType"] as IEnumerable<Data.Models.ToolType>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblTool');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("ToolUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityToolFormula" name="QuantityToolFormula" class="txt1 quantityTool quantity">
                                    </td>
                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblTool');"></div>
                                    </td>
                                </tr>
                            }

                        </tbody>
                    </table>
                </div>
                <div class="tablefooter">
                    <div class="pos1">
                        <input type="button" id="addline_CreateTool" class="addline" value="Thêm công cụ sản xuất">
                    </div>
                </div>
                <div class="cleardiv"></div>
                <div id="form_body">
                    <table id="tblLabour">
                        <thead>
                            <tr>
                                <th style="width: 90px;"><span>Ký hiệu</span></th>
                                <th style="width: 150px;"><span>Tên</span></th>
                                <th style="width: 150px;"><span>Mã chi tiết thiết kế</span></th>
                                <th style="width: 140px;"><span>Mã bậc thợ</span></th>
                                <th style="width: 100px;"><span>Đơn vị tính</span></th>
                                <th style="width: 50px;"><span>Số lượng</span></th>
                                <th style="width: 20px;"><span></span></th>
                            </tr>
                        </thead>
                        <tbody id="insertRow">
                            @if (Model.LabourFormulaFormModels != null)
                            {
                                if (Model.LabourFormulaFormModels.Count() > 0)
                                {
                                    foreach (var item in Model.LabourFormulaFormModels)
                                    { 
                                <tr>
                                    <td>
                                        <input type="hidden" id="LabourFormulaID" name="LabourFormulaID" value="@item.ID" class="LabourFormulaID" />
                                        <input type="text" id="CodeLabourFormula" name="CodeLabourFormula" class="txt1 codeLabour code" value="@item.Code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameLabourFormula" name="NameLabourFormula" class="txt1 nameLabour name" value="@item.Name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("LabourDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code", item.DesignDetailID), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("LabourTypeID", new SelectList(ViewData["Labour"] as IEnumerable<Data.Models.WorkerLevel>, "ID", "Name", item.WorkerLevelID), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblLabour');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("LabourUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name", item.UOMID), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityLabourFormula" name="QuantityLabourFormula" class="txt1 quantityLabour quantity" value="@item.Quantity">
                                    </td>

                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblLabour');"></div>
                                    </td>
                                </tr>
                                    }
                                }
                                else
                                {
                                <tr>
                                    <td>
                                        <input type="hidden" id="LabourFormulaID" name="LabourFormulaID" value="0" class="LabourFormulaID" />
                                        <input type="text" id="CodeLabourFormula" name="CodeLabourFormula" class="txt1 codeLabour code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameLabourFormula" name="NameLabourFormula" class="txt1 nameLabour name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("LabourDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code"), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("LabourTypeID", new SelectList(ViewData["Labour"] as IEnumerable<Data.Models.WorkerLevel>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblLabour');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("LabourUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityLabourFormula" name="QuantityLabourFormula" class="txt1 quantityLabour quantity">
                                    </td>
                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblLabour');"></div>
                                    </td>
                                </tr>
                                }

                            }
                            else
                            { 
                                <tr>
                                    <td>
                                        <input type="hidden" id="LabourFormulaID" name="LabourFormulaID" value="0" class="LabourFormulaID" />
                                        <input type="text" id="CodeLabourFormula" name="CodeLabourFormula" class="txt1 codeLabour code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameLabourFormula" name="NameLabourFormula" class="txt1 nameLabour name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("LabourDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code"), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("LabourID", new SelectList(ViewData["Labour"] as IEnumerable<Data.Models.WorkerLevel>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblLabour');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("LabourUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityLabourFormula" name="QuantityLabourFormula" class="txt1 quantityLabour quantity">
                                    </td>
                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblLabour');"></div>
                                    </td>
                                </tr>
                            }

                        </tbody>
                    </table>
                </div>
                <div class="tablefooter">
                    <div class="pos1">
                        <input type="button" id="addline_CreateLabour" class="addline" value="Thêm nhân công">
                    </div>
                </div>
                <div class="cleardiv"></div>
                <div id="form_body">
                    <table id="tblOther">
                        <thead>
                            <tr>
                                <th style="width: 90px;"><span>Ký hiệu</span></th>
                                <th style="width: 150px;"><span>Tên</span></th>
                                <th style="width: 150px;"><span>Mã chi tiết thiết kế</span></th>
                                <th style="width: 140px;"><span>Chi phí khác</span></th>
                                <th style="width: 100px;"><span>Đơn vị tính</span></th>
                                <th style="width: 50px;"><span>Số lượng</span></th>
                                <th style="width: 20px;"><span></span></th>
                            </tr>
                        </thead>
                        <tbody id="insertRow">
                            @if (Model.OtherCostFormulaFormModels != null)
                            {
                                if (Model.OtherCostFormulaFormModels.Count() > 0)
                                {
                                    foreach (var item in Model.OtherCostFormulaFormModels)
                                    { 
                                <tr>
                                    <td>
                                        <input type="hidden" id="OtherFormulaID" name="OtherFormulaID" value="@item.ID" class="OtherFormulaID" />
                                        <input type="text" id="CodeOtherFormula" name="CodeOtherFormula" class="txt1 codeOther code" value="@item.Code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameOtherFormula" name="NameOtherFormula" class="txt1 nameOther name" value="@item.Name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("OtherDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code", item.DesignDetailID), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("OtherTypeID", new SelectList(ViewData["Other"] as IEnumerable<Data.Models.OtherCost>, "ID", "Name", item.OtherCostID), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblOther');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("OtherUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name", item.UOMID), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityOtherFormula" name="QuantityOtherFormula" class="txt1 quantityOther quantity" value="@item.Quantity">
                                    </td>

                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblOther');"></div>
                                    </td>
                                </tr>
                                    }
                                }
                                else
                                {
                                <tr>
                                    <td>
                                        <input type="hidden" id="OtherFormulaID" name="OtherFormulaID" value="0" class="OtherFormulaID" />
                                        <input type="text" id="CodeOtherFormula" name="CodeOtherFormula" class="txt1 codeOther code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameOtherFormula" name="NameOtherFormula" class="txt1 nameOther name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("OtherDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code"), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("OtherTypeID", new SelectList(ViewData["Other"] as IEnumerable<Data.Models.OtherCost>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblOther');" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("OtherUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityOtherFormula" name="QuantityOtherFormula" class="txt1 quantityOther quantity">
                                    </td>
                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblOther');"></div>
                                    </td>
                                </tr>
                                }

                            }
                            else
                            { 
                                <tr>
                                    <td>
                                        <input type="hidden" id="OtherFormulaID" name="OtherFormulaID" value="0" class="OtherFormulaID" />
                                        <input type="text" id="CodeOtherFormula" name="CodeOtherFormula" class="txt1 codeOther code">
                                    </td>
                                    <td>
                                        <input type="text" id="NameOtherFormula" name="NameOtherFormula" class="txt1 nameOther name">
                                    </td>
                                    <td>
                                        @Html.DropDownList("OtherDesignDetailID", new SelectList(ViewData["DesignDetail"] as IEnumerable<Data.Models.DesignDetail>, "ID", "Code"), new { @class = "span2 col-sm-1 form-control desgingchange" })
                                    </td>
                                    <td>
                                        @Html.DropDownList("OtherID", new SelectList(ViewData["Other"] as IEnumerable<Data.Models.OtherCost>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control uom", @onchange="GetUOM(this,'tblMaterial');"})
                                    </td>
                                    <td>
                                        @Html.DropDownList("OtherUOMID", new SelectList(ViewData["UOM"] as IEnumerable<Data.Models.UOM>, "ID", "Name"), new { @class = "span2 col-sm-1 form-control unit" })
                                    </td>
                                    <td>
                                        <input type="text" id="QuantityOtherFormula" name="QuantityOtherFormula" class="txt1 quantityOther quantity">
                                    </td>
                                    <td>
                                        <div class="remove" id="delRow" onclick="RemoveRow(this,'tblOther');"></div>
                                    </td>
                                </tr>
                            }

                        </tbody>
                    </table>
                </div>
                <div class="tablefooter">
                    <div class="pos1">
                        <input type="button" id="addline_CreateOther" class="addline" value="Thêm chi phí khác">
                    </div>
                </div>
                <div class="cleardiv"></div>
                <div class="btn-group">
                    <div class="btn-group">
                        <button id="btnSaveSale" type="submit" class="btn btn-defaultxero">Ghi lại</button>
                    </div>
                </div>
                <div class="btn-group">
                    <button id="btnCancelSale" type="button" onclick="javascript: location.href = '/ProductModel';" class="btn btn-defaultxero">Hủy bỏ</button>
                </div>

            </div>
        </div>
    </form>
}

<script type="text/javascript">
    var $frtDesgin;
    var $frtMaterial;
    var $frtTool;
    var $frtOther;
    var $frtLabour;
    function RemoveRow(element, tbl) {
        var rowCount = $('#' + tbl + ' tbody tr').length;
        if (rowCount < 1) {
            return;
        }
        else {

            var tr = $(element).closest('tr');
            if (tbl == 'tblDesgin') {
                var designID = $(".designID", tr).val();
                if (designID != 0) {
                    $.ajax({
                        type: "POST",
                        url: '@Url.Action("Remove", "ProductModel")',
                        async: false,
                        cache: false,
                        data: { ID: designID },
                        success: function (result) {
                            //Xoa dong cac bang co type:designID
                            location.href = "/ProductModel/Create/" + $("#ID").val();
                        },
                        error: function (xhr, ajaxOptions, thrownError) {
                            alert(xhr.status);
                            alert(xhr.responseText);
                            alert(thrownError);
                        }
                    });
                    GetDesignDetail(designID, $("#ID").val());
                }
            }
            else {

                var code = $(".code", tr).val();
                var designID = $(".desgingchange", tr).val();

                if (designID == "") {
                    designID = 0;
                }
                if (code != null) {
                    $.ajax({
                        type: "POST",
                        url: '@Url.Action("RemoveDesign", "ProductModel")',
                        async: false,
                        cache: false,
                        data: { Code: code, Name: tbl, DesignID: designID },
                        success: function (result) {

                        },
                        error: function (xhr, ajaxOptions, thrownError) {
                            alert(xhr.status);
                            alert(xhr.responseText);
                            alert(thrownError);
                        }
                    });
                }

            }
            tr.remove();
        }
    };
    function GetUOM(element, tbl) {
        var tr = $(element).closest('tr');
        var code = $(".uom", tr).val();
        $.ajax({
            type: "GET",
            url: '@Url.Action("GetUOM", "ProductModel")',
                        async: false,
                        cache: false,
                        data: { Code: code, Name: tbl },
                        success: function (result) {
                            $(".unit", tr).val(result);
                            $(".quantity", tr).val(1);
                        },
                        error: function (xhr, ajaxOptions, thrownError) {
                            alert(xhr.status);
                            alert(xhr.responseText);
                            alert(thrownError);
                        }
         });
       
        
    };
    function RemoveAllRow(element) {
        alert(element);
    };
    
    $("#addline_CreateOther").click(function () {
        addTableRow('tblOther');
        return false;
    });
    $("#addline_CreateTool").click(function () {
        addTableRow('tblTool');
        return false;
    });
    $("#addline_CreateLabour").click(function () {
        addTableRow('tblLabour');
        return false;
    });
    $("#addline_CreateDesgign").click(function () {
        addTableRow('tblDesgin');
        return false;
    });
    $("#addline_CreateMaterial").click(function () {
        addTableRow('tblMaterial');
        return false;
    });
    function addTableRow(element) {
        var $tr = jQuery('div#form_body table#' + element).find("tbody tr:last").clone(true);
        if (typeof ($tr.html()) == "undefined") {
            if (element == 'tblDesgin') {
                jQuery('div#form_body table#' + element + ' tbody#insertRow').html($frtDesgin);
            }
            else if (element == 'tblMaterial') {
                jQuery('div#form_body table#' + element + ' tbody#insertRow').html($frtMaterial);
            }
            else if (element == 'tblTool') {
                jQuery('div#form_body table#' + element + ' tbody#insertRow').html($frtTool);
            }
            else if (element == 'tblLabour') {
                jQuery('div#form_body table#' + element + ' tbody#insertRow').html($frtLabour);
            }
            else if (element == 'tblOther') {
                jQuery('div#form_body table#' + element + ' tbody#insertRow').html($frtOther);
            }
        }
        else {
            jQuery('div#form_body table#' + element).find("tbody tr:last").after($tr);
        }
        $('.name', jQuery('div#form_body table#' + element).find("tbody tr:last")).val("");
        $('.code', jQuery('div#form_body table#' + element).find("tbody tr:last")).val("");
        $('.description', jQuery('div#form_body table#' + element).find("tbody tr:last")).val("");
        $('.desgingchange', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
        $('.accesscorychange', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
        $('.quantity', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(1);

        if (element == 'tblDesgin') {
            $('.designID', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
            $('.desginFile', jQuery('div#form_body table#' + element).find("tbody tr:last")).val("");
        }
        else if (element == 'tblMaterial') {
            $('.MaterialFormulaID', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
            $('.MaterialDesignDetailID', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
            $('#MaterialTypeID', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
        }
        else if (element == 'tblTool') {
            $('.ToolFormulaID', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
            $('.ToolDesignDetailID', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
            $('#ToolTypeID', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
        }
        else if (element == 'tblLabour') {
            $('.LabourFormulaID', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
            $('.LabourDesignDetailID', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
            $('#LabourTypeID', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
        }
        else if (element == 'tblOther') {
            $('.OtherFormulaID', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
            $('.OtherDesignDetailID', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
            $('#OtherTypeID', jQuery('div#form_body table#' + element).find("tbody tr:last")).val(0);
        }
    };
    $(document).ready(function () {
        $frtDesgin = "<tr><td><input type='hidden' id='designID' name='designID' value='0' class='designID'><input type='text' id='CodeDesgin' name='CodeDesgin' class='txt1 code'></td><td><input type='text' id='NameDesign' name='NameDesign' class='txt1 name'></td><td><select class='span2 col-sm-1 form-control type' id='TypeID' name='TypeID'><option value=''>Chọn kiểu</option><option value='0'>Toàn bộ</option><option value='1'>Chi tiết</option></select></td><td><input type='text' id='DescriptionDesign' name='DescriptionDesign' class='txt1 description'></td><td><input type='text' id='DesignFile' name='DesignFile' class='txt1 desginFile' onclick='SetFile(this);'></td><td><div class='addproduct' id='adddesign' onclick='AddDesign(this);'>Lưu</div></td><td><div class='remove' id='delRow' onclick='RemoveRow(this,\"tblDesgin\");'></div></td></tr>";
        $frtMaterial = jQuery('div#form_body table#tblMaterial').find("tbody tr:first").html();
        $frtLabour = jQuery('div#form_body table#tblLabour').find("tbody tr:first").html();
        $frtTool = jQuery('div#form_body table#tblTool').find("tbody tr:first").html();
        $frtOther = jQuery('div#form_body table#Other').find("tbody tr:first").html();

        //Ban đầu ẩn các phom chi tiết của chi tiết thiết kế
        $('.formChiTiet').hide();
        $(".materialchange").change(function () {
            ChangeProduct(this);
        });
        $(".desgingchange").change(function () {
            //GetDesignDetail(this);
        });
    });
    function GetDesignDetail(element, productID) {
        $.ajax({
            type: "GET",
            url: '@Url.Action("GetDesignDetail", "ProductModel")',
            async: false,
            cache: false,
            data: { ID: element, ProductID: productID },
            success: function (result) {
                if (result == true) {
                    //Dung cho material
                    $("#MaterialDesignDetailID").get(0).options.length = 0;
                    $("#MaterialDesignDetailID").get(0).options[0] = new Option("Chọn chi tiết thiết kế", "-1");
                    //Dung cho labour
                    $("#LabourDesignDetailID").get(0).options.length = 0;
                    $("#LabourDesignDetailID").get(0).options[0] = new Option("Chọn chi tiết thiết kế", "-1");
                    //Dung cho Tool
                    $("#ToolDesignDetailID").get(0).options.length = 0;
                    $("#ToolDesignDetailID").get(0).options[0] = new Option("Chọn chi tiết thiết kế", "-1");
                    //Dung cho Other
                    $("#OtherDesignDetailID").get(0).options.length = 0;
                    $("#OtherDesignDetailID").get(0).options[0] = new Option("Chọn chi tiết thiết kế", "-1");
                }
                else {
                    //Dung cho material
                    $("#MaterialDesignDetailID").get(0).options.length = 0;
                    //$("#MaterialDesignDetailID").get(0).options[0] = new Option("Chọn chi tiết thiết kế", "-1");
                    $.each(result, function (idx, obj) {
                        $("#MaterialDesignDetailID").get(0).options[$("#MaterialDesignDetailID").get(0).options.length] = new Option(obj.Code, obj.ID);
                    });
                    //Dung cho labour
                    $("#LabourDesignDetailID").get(0).options.length = 0;
                    //$("#LabourDesignDetailID").get(0).options[0] = new Option("Chọn chi tiết thiết kế", "-1");
                    $.each(result, function (idx, obj) {
                        $("#LabourDesignDetailID").get(0).options[$("#LabourDesignDetailID").get(0).options.length] = new Option(obj.Code, obj.ID);
                    });
                    //Dung cho Tool
                    $("#ToolDesignDetailID").get(0).options.length = 0;
                    //$("#ToolDesignDetailID").get(0).options[0] = new Option("Chọn chi tiết thiết kế", "-1");
                    $.each(result, function (idx, obj) {
                        $("#ToolDesignDetailID").get(0).options[$("#ToolDesignDetailID").get(0).options.length] = new Option(obj.Code, obj.ID);
                    });
                    //Dung cho Other
                    $("#OtherDesignDetailID").get(0).options.length = 0;
                    //$("#OtherDesignDetailID").get(0).options[0] = new Option("Chọn chi tiết thiết kế", "-1");
                    $.each(result, function (idx, obj) {
                        $("#OtherDesignDetailID").get(0).options[$("#OtherDesignDetailID").get(0).options.length] = new Option(obj.Code, obj.ID);
                    });
                }

            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(xhr.responseText);
                alert(thrownError);
            }
        });
    }
</script>
